package com.zx.map.controller.timer;
import com.zx.map.dao.NoticeLogDao;
import com.zx.map.dao.model.NoticeLog;
import com.zx.map.dao.model.NoticeLogExample;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class UpdateNoticeDateTimer {
	private static Logger log = Logger.getLogger(UpdateNoticeDateTimer.class);
	@Autowired
	private NoticeLogDao noticeLogDao;

	public void updateEffectiveDate() throws ParseException {
		log.info("更改公告影响时间开始");
		NoticeLogExample example = new NoticeLogExample();
		NoticeLogExample.Criteria criteria = example.createCriteria();
		criteria.andNoticeIdEqualTo(11);
		List<NoticeLog> list = noticeLogDao.getListByExample(example);
		NoticeLog noticeLog = list.get(0);
		Date date=new Date();
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = "2017-02-02";
		String time=format.format(date);
		Date d = parseDate(dateStr);//将字符串转换成date类型
		Date t = parseDate(time);
		if(t.getTime() < d.getTime()){
			noticeLog.setEffectiveDate(time);
			noticeLogDao.update(noticeLog);
			log.info("更改公告影响时间结束");
		}else{
			System.out.print("说明春节结束了，蓝瘦，香菇！");
		}
	}
	//将字符串转换成date类型方法
	static public Date parseDate(String s) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		return format.parse(s);
	}

}
